using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;
using System.Collections.Generic;

namespace Pay.Service.AutoMapper {
	public class OrderItemMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public OrderItemMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<order_item_dto, OrderItem>()
				.ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
				.ForMember(dest => dest.OrderId, src => src.MapFrom(c => c.order_id))
				.ForMember(dest => dest.ProductId, src => src.MapFrom(c => c.product_id))
                .ForMember(dest => dest.BazaarProductId, src => src.MapFrom(c => c.bazaar_product_id))
                .ForMember(dest => dest.Quantity, src => src.MapFrom(c => c.quantity))
                .ForMember(dest => dest.SkuId, src => src.MapFrom(c => c.sku_id))
                .ForMember(dest => dest.SkuPath, src => src.MapFrom(c => c.sku_path))
				.ForMember(dest => dest.SkuName, src => src.MapFrom(c => c.sku_name))
				.ForMember(dest => dest.UnitPrice, src => src.MapFrom(c => c.unit_price))
				.ForMember(dest => dest.ProductName, src => src.MapFrom(c => c.product_name))
				.ForMember(dest => dest.ThumbnailsUrl, src => src.MapFrom(c => c.thumbnails_url))
                .ForMember(dest => dest.Product, src => src.MapFrom(c => c.product))
                .ForMember(dest => dest.TokenBazaarProduct, src => src.MapFrom(c => c.bazaar_product))
                .ForMember(dest => dest.MarketPrice, src => src.MapFrom(c => c.market_price))
				.ForMember(dest => dest.IntegralRate, src => src.MapFrom(c => c.integral_rate))
				.ForMember(dest => dest.Points, src => src.MapFrom(c => c.points))
                .ForMember(dest => dest.DistributionId, src => src.MapFrom(c => c.distribution_id))
                .ForMember(dest => dest.GrossWeight, src => src.MapFrom(c => c.grossweight))
                .ForMember(dest => dest.LegalWeight, src => src.MapFrom(c => c.legalweight))
                .ForMember(dest => dest.ProductActivityId, src => src.MapFrom(c => c.product_activity_id))
                .ForMember(dest => dest.IsCashPay, src => src.MapFrom(c => c.isCashPay))
                .ForMember(dest => dest.RedDrill, src => src.MapFrom(c => c.red_drill))
                .ForMember(dest => dest.ActiveType, src => src.MapFrom(c => c.active_type))
                .ForMember(dest => dest.OrderItemType, src => src.MapFrom(c => c.order_item_type))
                .ForMember(dest => dest.Body, src => src.MapFrom(c => c.body.ToJson()))
				.ForMember(dest => dest.Product, src => src.Ignore())
				.ForMember(dest => dest.Order, src => src.Ignore());
			_cfg.CreateMap<OrderItem, order_item_dto>()
				.ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.order_id, src => src.MapFrom(c => c.OrderId))
				.ForMember(dest => dest.product_id, src => src.MapFrom(c => c.ProductId))
                .ForMember(dest => dest.bazaar_product_id, src => src.MapFrom(c => c.BazaarProductId))
                .ForMember(dest => dest.product, src => src.MapFrom(c => c.Product))
                    .ForMember(dest => dest.bazaar_product, src => src.MapFrom(c => c.TokenBazaarProduct))
                .ForMember(dest => dest.quantity, src => src.MapFrom(c => c.Quantity))
                .ForMember(dest => dest.sku_id, src => src.MapFrom(c => c.SkuId))
                .ForMember(dest => dest.sku_path, src => src.MapFrom(c => c.SkuPath))
				.ForMember(dest => dest.sku_name, src => src.MapFrom(c => c.SkuName))
				.ForMember(dest => dest.unit_price, src => src.MapFrom(c => c.UnitPrice))
				.ForMember(dest => dest.product_name, src => src.MapFrom(c => c.ProductName))
				.ForMember(dest => dest.thumbnails_url, src => src.MapFrom(c => c.ThumbnailsUrl))
				.ForMember(dest => dest.market_price, src => src.MapFrom(c => c.MarketPrice))
				.ForMember(dest => dest.integral_rate, src => src.MapFrom(c => c.IntegralRate))
                .ForMember(dest => dest.distribution_id, src => src.MapFrom(c => c.DistributionId))
                .ForMember(dest => dest.points, src => src.MapFrom(c => c.Points))
                .ForMember(dest => dest.grossweight, src => src.MapFrom(c => c.GrossWeight))
                .ForMember(dest => dest.legalweight, src => src.MapFrom(c => c.LegalWeight))
                .ForMember(dest => dest.isCashPay, src => src.MapFrom(c => c.IsCashPay))
                .ForMember(dest => dest.red_drill, src => src.MapFrom(c => c.RedDrill))
                .ForMember(dest => dest.product_activity_id, src => src.MapFrom(c => c.ProductActivityId))
                .ForMember(dest => dest.active_type, src => src.MapFrom(c => c.ActiveType))
                .ForMember(dest => dest.order_item_type, src => src.MapFrom(c => c.OrderItemType))
                .ForMember(dest => dest.body, src => src.MapFrom(c => c.Body.ToObject<Dictionary<string, object>>()));
		}
	}
}
